import config from '../config'

export type ImageMapKey = keyof typeof config.images // 声明成这样，使用get的时候就有提示

export const image = new Map<ImageMapKey, HTMLImageElement>()

// 图片异步加载，返回promise数组
export const promises = Object.entries(config.images).map(([key, value]) => {
  return new Promise((resolve) => {
    const img = document.createElement('img')
    img.src = value
    img.onload = () => {
      image.set(key as ImageMapKey, img)
      resolve(img)
    }
  })
})
